﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QWidget>
#include<QTcpSocket>
#include <QTcpSocket>
#include <QHostAddress>
#include<QTabWidget>
#include<QPixmap>
#include<QDebug>
#include<QStringList>
#include<QFileDialog>
#include<QMovie>
#include<QPixmap>
#include<QPainter>
#include <QTcpServer>
#include <QTcpSocket>
#include <QWidget>
#include <QListWidgetItem>
#include<QKeyEvent>
#include<QProcess>

#include <QContextMenuEvent>
#include <QMenu>
#include <QAction>
#include <QMouseEvent>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QMessageBox>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QPainter>
#include<QMovie>

#include "weatherdata.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
private:
    void onReplied(QNetworkReply*erply);//请求数据成功调用此函数
private:
    Ui::MainWindow *ui;
private slots:
    //void onReplied(QNetworkReply* reply);
    void on_btnSearch_clicked();
    void on_Cityline_returnPressed();
    void on_pushButton_clicked();

protected:
    void contextMenuEvent(QContextMenuEvent *event);
    //获取天气数据,解析JSON，更新UI
    void getWeatherInfo(QString cityCode);
    void parseJson(QByteArray &byteArray);
    void updateUI();
    bool eventFilter(QObject *watched, QEvent *event) override; //重写绘图事件
    //绘制曲线
    void paintHight();
    void paintLow();
private:
    QMenu* mExitMenu; //右键退出的菜单
    QAction* mExitAction; //退出的行为-菜单项
    QPoint mOffset;  //窗口移动时，鼠标与天气界面窗口左上角的偏移
    QNetworkAccessManager *mNetAccessManager;//请求数据
    Today mToday;
    Day mDay[6];
    QList<QLabel* > mWeekList;
    QList<QLabel* > mDateList;
    //天气和天气图标
    QList<QLabel* > mTypeList;
    QList<QLabel* > mTypeIconList;
    QList<QLabel* > mTypeIconListgif;
    //天气污染指数，优……
    QList<QLabel* > mAqiList;
    //风向，风力
    QList<QLabel* > mFxList;
    QList<QLabel* > mFlList;
    QMap<QString,QString>mTypeIconMap;
    QMap<QString, QMovie*> mTypeIconMapgif;
    QMap<QString, QString> animationPaths;
    //城市编码
    QMap<QString,QString> mCityMap;
protected:
    void initCityCode(); // 初始化城市数据,读取解析一个json文件，将数据存到map里面
};
#endif // MAINWINDOW_H
